<?php
/**
 * Created by PhpStorm.
 * User: peter
 * Date: 2018/12/4
 * Time: 8:52 AM
 */

namespace app\activity\controller;


use app\activity\logic\Configure;
use extend\Functions;
use extend\STATUS_CODE;
use think\Request;

class Version extends Base
{
    /**
     * @purpose 客户端检测资源升级
     * @param Request $request
     * @return array
     */
    public function checkWgt (Request $request)
    {
        $os     = strtolower($request->get('os'));
        $version = $request->get('v');

        $data = Configure::getConfigure('upgrade_wgt_'.$os);
        if ($data['code'] !== 10000 || empty($data['data'])) {
            return Functions::result(
                STATUS_CODE::SUCCESS,
                [
                    'status' => 1
                ]
            );
        }
        $data = $data['data'];
        if ((float) $version >= (float) $data['version']) {
            return Functions::result(
                STATUS_CODE::SUCCESS,
                [
                    'status' => 1
                ]
            );
        }
        if (!$data['switch']) {
            return Functions::result(
                STATUS_CODE::SUCCESS,
                [
                    'status' => 1
                ]
            );
        }
        $data['status'] = 2;
        return Functions::result(STATUS_CODE::SUCCESS,$data);
    }
    /**
     * @purpose 客户端检测资源升级
     * @param Request $request
     * @return array
     */
    public function check (Request $request)
    {
        $os         = strtolower($request->get('os'));
        $version    = strtolower($request->get('v'));

        $data = Configure::getConfigure('upgrade_'.$os);
        if ($data['code'] !== 10000 || empty($data['data'])) {
            return Functions::result(
                STATUS_CODE::SUCCESS,
                [
                    'status' => 1
                ]
            );
        }
        $data = $data['data'];
        if ((float) $version >= (float) $data['version']) {
            return Functions::result(
                STATUS_CODE::SUCCESS,
                [
                    'status' => 1
                ]
            );
        }
        if (!$data['switch']) {
            return Functions::result(
                STATUS_CODE::SUCCESS,
                [
                    'status' => 1
                ]
            );
        }
        $data['status'] = 2;
        return Functions::result(STATUS_CODE::SUCCESS, $data);
    }
}